home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / rdflib / sparql / bison / Util.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  1.8 KB  |  40 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4.  
  5. class ListRedirect(object):
  6.     '''
  7.     A utility class for lists of items joined by an operator.  ListRedirects with length 1
  8.     are a special case and are considered equivalent to the item instead of a list containing it.
  9.     The reduce function is used for normalizing ListRedirect to the single item (and calling reduce on it recursively)
  10.     '''
  11.     reducable = True
  12.     
  13.     def __getattr__(self, attr):
  14.         if hasattr(self._list, attr):
  15.             return getattr(self._list, attr)
  16.         raise AttributeError, '%s has no such attribute %s' % (repr(self), attr)
  17.  
  18.     
  19.     def __iter__(self):
  20.         for i in self._list:
  21.             yield i
  22.         
  23.  
  24.     
  25.     def reduce(self):
  26.         if self.reducable and len(self._list) == 1:
  27.             singleItem = self._list[0]
  28.             if isinstance(singleItem, ListRedirect):
  29.                 return singleItem.reduce()
  30.             return singleItem
  31.         len(self._list) == 1
  32.         return []([ item for item in self._list ])
  33.  
  34.  
  35.  
  36. def ListPrepend(item, list):
  37.     return [
  38.         item] + list
  39.  
  40.